<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <Sticky>
            <user-card :user="user1" />
          </Sticky>
        </el-col>

        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="文章" name="MyArticleList">
                <MyArticleList :user-id="user.userId" />
              </el-tab-pane>
              <el-tab-pane label="收藏" name="MyCollectionList">
                <MyCollectionList />
              </el-tab-pane>
              <el-tab-pane label="账户" name="Account">
                <account :user="user" />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/UserCard'
import MyArticleList from './components/MyArticleList'
import MyCollectionList from './components/MyCollectionList'
import Account from './components/Account'
import { getUserById } from '@/api/user'
import Sticky from '@/components/Sticky'
export default {
  name: 'Profile',
  components: { Sticky, UserCard, MyArticleList, MyCollectionList, Account },
  data() {
    return {
      user: null,
      user1: null,
      activeTab: 'MyArticleList'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles',
      'introduction',
      'id',
      'pet'

    ])
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      getUserById(this.id).then(res => {
        this.user = res.data.user
        this.user1 = {
          name: this.name,
          role: this.roles.join(' | '),
          avatar: this.avatar,
          pet: this.pet,
          introduction: this.introduction
        }
      }).catch(error => {
        console('无法查出用户信息')
      })
    }
  }
}
</script>
